<?php
	include_once "../conf/conf.site.inc.php";
	include_once "class.mysql.php";
	include_once "functions.php";
	
	class parent_class {
		var $objMysql;
	
		// Constructeur
		function parent_class ($conn = false) {
			if ($conn) {
				$this->objMysql = $conn;
			}
			else {
				$this->objMysql = connexion();
			}
		}
		
		// Destructeur
		function _parent_class () {
			deconnexion();
		}
		
		function parentSearch ($nom = "", $prenom = "") {
			$reqGetParent = "SELECT AU.NOM, AU.PRENOM, AP.ID_PARENT
							FROM arabe_user AU
							INNER JOIN arabe_parent AP ON AP.ID_USER = AU.ID_USER
							";
			if ($nom != "") {
				$reqGetParent .= "WHERE AU.NOM LIKE '%" . $nom . "%'";
			}
			
			else 
				if ($prenom != "") {
					$reqGetParent .= "WHERE AU.PRENOM LIKE '%" . $prenom . "%'";
				}
			
			$result = $this->objMysql->MysqlSelectPerso($reqGetParent);
			if (count($result) > 0) {
				return $result;
			}
			else {
				return 0;
			}
		}
		
		function createNewUser ($login, $password, $email, $nom, $prenom) {
			$values = array ("LOGIN" => $login,
					"PASSWORD" => $password,
					"EMAIL" => $email,
					"NOM" =>  $nom,
					"PRENOM" => $prenom,
                                        "DATE_CREATION" => date("Y-m-d H:i:s"),
                                        "DATE_MODIF" => date("Y-m-d H:i:s"));
								
			$result = $this->objMysql->MysqlInsert("arabe_user", $values);
			if ($result) {
				return $this->objMysql->DernierID;
			}
			else {
				return false;
			}
		}
		
		function createNewParent ($idUser, $numTel, $adresse) {
			$values = array ("ID_USER" => $idUser,
					"ADRESSE" => $adresse,
					"NUM_TEL" => $numTel);
								
			$result = $this->objMysql->MysqlInsert("arabe_parent", $values);
			if ($result) {
				return $this->objMysql->DernierID;
			}
			else {
				return false;
			}
		}
	}
?>